package com.epam.employeebase.command;

import java.util.concurrent.ConcurrentHashMap;

import com.epam.employeebase.controller.RequestContent;

public final class CommandManager {
	private static final String COMMAND_PARAMETER_NAME = "command";
	private static ConcurrentHashMap<CommandType, Command> commands = new ConcurrentHashMap<CommandType, Command>();
	
	static {
		commands.put(CommandType.EMPLOYEELIST, new EmployeeListCommand());
		commands.put(CommandType.MAIN, new MainCommand());
		commands.put(CommandType.CHOOSEDAO, new ChooseDAOCommand());
		commands.put(CommandType.CHANGEENTRIESPERPAGE, new ChangeEntriesPerPageCommand());
	}
	
	private CommandManager() {}
	
	public static Command getCommand(RequestContent requestContent){
		String commandName = requestContent.getRequestParameter(COMMAND_PARAMETER_NAME);
		CommandType commandType = CommandType.valueOf(commandName.toUpperCase());
		Command command = commands.get(commandType);
		return command;
	}
	
	public static Command getCommand(CommandType commandType){
		return commands.get(commandType);
	}
}
